
<template>
  <div class="main">
    <el-card class="box-card">
      <div>
        <div class="header-container">
          <div class="block-before"></div>
          <span class="v-title">视频名称</span>
        </div>
        <search-tool @onSearch="handleSearch"></search-tool>
        <div class="treeBox">
          <el-scrollbar height="100%">
            <el-tree
              :data="data"
              :props="defaultProps"
              :highlight-current="true"
              node-key="id"
              default-expand-all
              accordion
              @node-click="handleNodeClick"
            />
          </el-scrollbar>
        </div>
      </div>
    </el-card>
    <div class="playVdeo">
      <FlvPlayer
        v-if="VideoInfo && VideoInfo.url"
        :video-path="VideoInfo.url"
        :video-id="VideoInfo.id + 'camera_view'"
        style="height: 100%; border-radius: 0.15625rem"
      />
    </div>
  </div>
</template>

<script setup>
import { reactive, ref } from 'vue'
// import FlvPlayer from '@/components/FlvPlayer/index.vue'
import FlvPlayer from '@/components/FlvPlayer/index.vue'
import SearchTool from './components/SearchTool/index.vue'
import { VideoTree } from '@/api/monitor.js'

const data = ref([])
const VideoInfo = ref()
const parms = ref({})
const defaultProps = reactive({
  children: 'assemanagements',
  label: 'equipmentName'
})

const handleNodeClick = (res) => {
  if (res.assemanagements) {
    return
  }
  VideoInfo.value = res
  console.log(VideoInfo.value)
}
const loopData = (datas) => {
  if (datas.assemanagements) {
    VideoInfo.value = datas.assemanagements[0]
  }
  if (datas.assemanagements && datas.assemanagements.length > 0) {
    loopData(datas.assemanagements[0])
  } else {
    return VideoInfo.value
  }
}
const List = async (value) => {
  const res = await VideoTree(value)
  data.value = res.videoInfosResponses
  loopData(res.videoInfosResponses[0])
}

const handleSearch = (res) => {
  List(res || '')
}
handleSearch()
</script>

<style lang="scss" scoped>
.main {
  position: relative;
  height: 100%;
  .box-card {
    width: 282px;
    height: 100%;
    .header-container {
      display: flex;
      .block-before {
        width: 5px;
        height: 16px;
        background: #1d6ae6;
        opacity: 1;
        border-radius: 11px;
      }
      .v-title {
        margin-top: 7px;
        margin-left: 8px;
        margin-bottom: 30px;
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        line-height: 0px;
        color: #16171c;
      }
    }
    .treeBox {
      height: 700px;
    }
  }
  .playVdeo {
    position: absolute;
    top: 1px;
    right: 0;
    width: 82%;
    height: 99.8%;
    border-radius: 0.15625rem;
    box-shadow: var(--el-box-shadow-light);
  }
}
</style>
